import requests
import jmespath
from loguru import  logger

def select_label():
    headers = {
        'Accept' : 'application/json, text/plain, */*',
        'Accept-Language' : 'zh-CN,zh;q=0.9',
        'Connection' : 'keep-alive',
        'Referer' : 'http://124.70.39.201/admin/member/label',
        'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
        'lang' : 'zh-cn',
        'token' : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTc0NDM2MzI3MywibmJmIjoxNzQ0MzYzMjczLCJleHAiOjE3NDQ5NjgwNzMsImp0aSI6IjFfYWRtaW4ifQ.T-g3-TwaCE5Sxh8u7V5Sg8DPb2rJ_iZUU29ETJdSIWA',
    }

    params = {
        'page' : '1',
        'limit' : '10',
        'label_name' : '',
    }
    response = requests.get('http://124.70.39.201/adminapi/member/label', params=params, headers=headers)
    return response.json()
def delect_label(d_id):
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Origin': 'http://124.70.39.201',
        'Referer': 'http://124.70.39.201/admin/member/label',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTc0NDM2MzI3MywibmJmIjoxNzQ0MzYzMjczLCJleHAiOjE3NDQ5NjgwNzMsImp0aSI6IjFfYWRtaW4ifQ.T-g3-TwaCE5Sxh8u7V5Sg8DPb2rJ_iZUU29ETJdSIWA',
    }

    response = requests.delete(f'http://124.70.39.201/adminapi/member/label/5 13', headers=headers, verify=False)


while True:
    ids = jmespath.search("data.data[*].label_id", select_label())
    if len(ids) > 0 :
        break
    logger.debug(f"删除id:{ids[0]}")
    delect_label(ids[0])       ##删除所有数据
    # for i in ids:
        # delect_label(i)      ##删除一页数据
